derivative of cost function